package domain.models;

import java.util.ArrayList;
import java.util.List;

import controllers.DomainController;
import controllers.MyObserver;

import domain.*;

public class GamesTableModel extends MyTableModel implements MyObserver {
	List<Game> data;
	private boolean areInProgress;
	
	public GamesTableModel(DomainController domainController, boolean areInProgress) {
		super(domainController);
		String[] columnHeadersGamesTable = {"Witte speler", "Zwarte speler", "Uitslag", "Datum einde spel"};
		//super.setColumnHeaders(columnHeadersGamesTable);
		//data = (areInProgress ? domainController.showGamesInProgress() : domainController.showGamesPlayed());
		this.areInProgress = areInProgress;
		if(!areInProgress)
		{
			super.setColumnHeaders(columnHeadersGamesTable);
			data = domainController.showGamesPlayed();
		}
		else
		{
			super.setColumnHeaders(new String[]{"Witte speler", "Zwarte speler", "Uitslag"});
			data = domainController.showGamesInProgress();
		}
		domainController.getCurrentTournament().addObserver(this);
	}

	@Override
	public Object getValueAt(int rowI, int colI) {
		return data.get(rowI).toArray()[colI]; 
	}

	@Override
	public int getRowCount() {
		return data.size();
	}

	@Override
	public void update(String adressee) {
		if(this.getClass().toString().contains(adressee))
		{
			data = (areInProgress ? domainController.showGamesInProgress() : domainController.showGamesPlayed());
			this.fireTableDataChanged();
		}
	}
}
